home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- (c) 1984-1993 by Scientific Endeavors Corporation.
- All rights reserved.
-
- This program demonstrates a semi-log plot with a legend, a linear plot
- with a window, and a semi-log plot with left and right y axes and
- upright y labels.
- ****************************************************************************/
- #include <graphic.h> /* Include all needed files */
-
- #if TCQ /* Set stack for Borland (Turbo) C */
- extern unsigned _stklen = 0x3000;
- #endif
-
- /* Declare variables here so they don't go on the stack */
- static char *xstring[] = { /* Strings for X-Axis labels */
- "1984", "1985", "1986", "1987", "1988", "1989"
- };
- static float u1[62] = { /* u1 is the Company stock fund */
- 6.74, 7.3, 8.61, 9.29, 9.74, 10., 9.676, 10.6038, 11.7344, 11.3485,
- 13.7248, 12.7133, 13.4976, 15.498, 16.3235, 15.8140, 15.7405, 17.8188,
- 17.8277, 18.0340, 17.734, 15.2812, 15.2875, 16.172, 16.671, 15.6087,
- 17.9595, 20.7653, 20.9448, 22.5165, 22.1078, 20.95, 22.9562, 20.9474,
- 19.1381, 21.3239, 18.8562, 21.7838, 22.8548, 24.4238, 21.9162, 21.9184,
- 22.967, 24.9581, 26.3963, 27.2202, 19.4238, 18.9284, 20.9032, 23.4342,
- 23.3657, 22.2842, 21.2772, 20.5066, 22.5556, 20.7719, 19.7649, 21.7906,
- 22.5653, 21.3561, 20.6527, 21.562
- };
- static float u2[62] = { /* u2 is the Fixed Income Fund */
- 24.9266, 25.1392, 25.3568, 25.5743, 25.8139, 26.0681, 26.3109, 26.5607,
- 26.8234, 27.0789, 27.3422, 27.6022, 27.8693, 28.1191, 28.3711, 28.6253,
- 28.8833, 29.1397, 29.3996, 29.6653, 29.9315, 30.2079, 30.4776, 30.7508,
- 31.047, 31.3164, 31.5869, 31.8565, 32.1266, 32.3961, 32.6705, 32.95,
- 33.2245, 33.5053, 33.7878, 34.0731, 34.4021, 34.6832, 34.9363, 35.2175,
- 35.4915, 35.7733, 36.0476, 36.3593, 36.627, 36.9042, 37.1871, 37.4632,
- 37.7509, 38.0319, 38.2865, 38.5704, 38.8489, 39.1397, 39.4259, 39.7232,
- 40.0245, 40.3181, 40.6301, 40.932, 41.2492, 41.5818
- };
- static float u3[62] = { /* u3 is the Equity Fund */
- 18.26, 18.2983, 18.346, 17.4876, 17.7345, 16.9745, 17.33, 17.087,
- 18.6332, 18.7496, 18.7721, 18.7327, 19.4395, 20.4982, 20.6580, 21.0312,
- 21.3133, 22.2778, 22.8659, 22.681, 22.684, 22.1318, 23.2726, 24.388,
- 25.2836, 25.6543, 27.4712, 29.1251, 28.4984, 29.6629, 30.1036, 28.98,
- 31.5469, 29.8584, 30.4436, 30.8878, 30.6971, 33.8124, 34.8253, 35.8124,
- 36.322, 36.57, 38.0806, 38.6662, 40.3914, 38.4364, 31.9274, 29.2592,
- 31.0548, 34.7917, 35.4516, 34.3014, 34.6729, 35.8435, 38.9324, 38.7803,
- 37.4419, 39.6724, 40.7028, 40.1896, 40.1600, 43.6935
- };
-
- #ifdef ANSI
- void GPC_MAIN(void)
- #else
- void GPC_MAIN()
- #endif
- {
- float t[62];
- double x1a, pi = 3.141592654;
- int nxdiv, nydiv, npts;
- float shrs1[62], shrs2[62], shrs3[62], vl1[62], vl2[62], vl3[62];
- float taly1, taly2, taly3;
- int i, inum1, inum1m;
- G_PFQ(x, hx);
- G_PFQ(y, hy);
- G_PFQ(z, hz);
-
- x = (float DIST *)GPC_ALLOC(&hx, 301, sizeof(float));
- y = (float DIST *)GPC_ALLOC(&hy, 301, sizeof(float));
- z = (float DIST *)GPC_ALLOC(&hz, 301, sizeof(float));
- if (x == (void DIST *)NULL || y == (void DIST *)NULL ||
- z == (void DIST *)NULL) {
- GPC_PUTS("CLRTEST: Could not allocate data arrays");
- goto FreeMem;
- }
- inum1 = 62; /* Generate data points */
- inum1m = inum1-1;
- taly1 = 0.;
- taly2 = 0.;
- taly3 = 0.;
- for(i = 0; i <= inum1m; i++) {
- t[i] = i;
- taly1 = taly1 + 1. / u1[i];
- shrs1[i] = taly1;
- vl1[i] = shrs1[i] * u1[i];
-
- taly2 = taly2 + 1. / u2[i];
- shrs2[i] = taly2;
- vl2[i] = shrs2[i] * u2[i];
-
- taly3 = taly3 + 1. / u3[i];
- shrs3[i] = taly3;
- vl3[i] = shrs3[i] * u3[i];
- }
-
- bgnplot(1, 'g', "clr.tkf"); /* GraphiC initialization */
- startplot(BLACK);
- metricunits(0); /* Plots are in inches */
- font(2, "complex.fnt", '\310', "microb.fnt", '\311'); /* Select fonts */
- rotate(1); /* Plot is rotated */
-
- page(6.884f, 9.0f); /* Size of page and plot area */
- area2d(5.5f, 7.6f);
-
- color(WHITE);
- tcurve(4); /* Curves will be 4 pixels thick */
- legpos(3, 2.5, 2.5, 1); /* Draw legend */
- legend(1, "Company", 1, .14, 9);
- legend(1, "Fixed Income", 4, .14, 12);
- legend(1, "Equity Fund", 9, .14, 13);
-
- yname("Price ($ per unit)"); /* Axis and plot titles */
- heading("\311Savings Plan Values\310");
- frame(1,1); /* Semi-log axis with frame, */
- grid(2); /* Dotted grid, and */
- fgrid(0,0);
- xlab(1,xstring); /* String labels */
- ylog("", 0., 12., 59., 6., 60.);
- xlab(0,xstring);
-
- curve((float DIST *)t, (float DIST *)u1, inum1, 0);
- curve((float DIST *)t, (float DIST *)u2, inum1, 0);
- curve((float DIST *)t, (float DIST *)u3, inum1, 0);
- tcurve(0);
-
- if (endplot()) /* Terminate first plot */
- goto EndOfApp;
-
- startplot(MAGENTA); /* GraphiC initialization (2nd plot) */
- font(3, "simplex.fnt", '\310', "triplex.fnt", '\311', /* Select fonts */
- "complex.fnt", '\312');
- rotate(0); /* Non rotated picture */
-
- page(9.0f, 6.884f); /* Size of page and plot area */
- area2d(7.6f, 5.5f);
-
- gwindow(4.0, 1.0, 8.8, 4.25); /* Define area for window */
-
- color(YELLOW); /* Axis and plot titles */
- xname("\312X axis");
- yname("\312Y axis");
- heading("\311WINDOW SAMPLE");
-
- npts=301; /* Generate data points */
- for(i = 0; i < npts; i++) {
- y[i] = .3 * i;
- x[i] = (y[i] * y[i]) / 2;
- }
-
- color(BLACK);
- nxdiv=5; /* Desired # of x-axis divisions */
- nydiv=6; /* Desired # of y-axis divisions */
- frame(0,0); /* Turn off frame */
- fgrid(0,0); /* Turn off grid subdivision */
- grid(9); /* Fine dot grid at tick marks */
- box();
- scales(nxdiv, nydiv, (float DIST *)x, (float DIST *)y, npts);
-
- color(BRT_WHITE);
- dashf(6);
- curve((float DIST *)x, (float DIST *)y, npts, 0); /* Draw curve only */
- endplot();
-
- /*
- The following calls assume that the plot fills the entire screen.
- However, all plot elements will be scaled to fit within the area
- defined in the call to gwindow(). setscale(1) turns this mode on.
- */
- startplot(MAGENTA);/* Start the picture that goes in the windowed area */
- setscale(1); /* Turn on font scaling */
- font(2, "swissbld.fnt", '\310', "triplex.fnt", '\311');/* Select fonts */
- fillfont(1);
-
- color(BLACK); /* Draw black box around plot */
- box();
-
- color(BLUE); /* Plot blue text in the window */
- tmargin(1.75);
- lmargin(.25);
- ltline("\310GraphiC \311allows you to leave an", .325);
- ltline("\311area within a plot clear and", .325);
- ltline("\311create a new plot in the clear", .325);
- ltline("\311area.", .325);
-
- setscale(0); /* Turn off font scaling */
-
- if (endplot()) /* Terminate 2nd plot */
- goto EndOfApp;
-
- startplot(BLACK); /* GraphiC initialization (3rd plot) */
- font(4, "simplex.fnt", '\310', "triplex.fnt", '\311', /* Select fonts */
- "complex.fnt", '\312', "compgrma.fnt", '\313');
-
- page(9.0f, 6.884f); /* Size of page and plot area */
- area2d(6.4f, 5.5f);
-
- color(MAGENTA); /* Draw magenta legend */
- legpos(2, 5.3, 5.1, 1);
- legend(1, "Amplitude", 1, .125, 14);
- legend(1, "Phase", 4, .125, 12);
-
- pbox(); /* Draw a box around the plot */
- xname("\312Frequency"); /* x axis label */
- yname("\312Amplitude"); /* y axis label */
- heading("\311Filter Response"); /* Plot title */
-
- color(WHITE);
- nxdiv=10; /* Desired # of x axis divisions */
- nydiv=6; /* Desired # of y axis divisions */
- grid(2); /* Grid lines on the x-axis only */
- fgrid(-1, 5); /* Subdivide axes with tick marks only */
- frame(1,0); /* Frame the plot with no tick marks */
- rightax(1); /* Second y-axis will be on the right */
- upright(1); /* y-axis labels are to be upright */
- xlog(0.05, 10.0, "%-1.2f", 0.0, 0.4, 2.4);
-
- npts = 200; /* Generate data points */
- for(i = 1; i <= 200; i++) {
- x[i-1] = (float)i / 20.;
- x1a = x[i-1] * x[i-1];
- y[i-1] = 1 / sqrt((double)((1 - x1a) * (1 - x1a)) +
- ((.5 * x[i-1]) * (.5 * x[i-1])));
- if(i == 20)
- z[i-1] = pi / 2;
- else
- z[i-1] = -atan((double)(.5 * x[i-1] / (1. - x1a)));
- if(z[i-1] > 0)
- z[i-1] -= pi;
- }
-
- curve((float DIST *)x, (float DIST *)y, npts, 0); /* Draw curve only */
-
- color(MAGENTA);
- yname("\312Phase in Radians"); /* Right-hand y axis label */
-
- color(WHITE);
- frame(0, 0); /* Do not redraw frame */
- fgrid(0, 0); /* Do not subdivide plot */
- xlog(0.05, 10.0, "%-1.1f", -3.6, 0.6, 0.0); /* Draw right-hand y-axis */
-
- curve((float DIST *)x, (float DIST *)z, npts, 0); /* Draw curve only */
-
- dateit('\312'); /* Put date and time on plot */
-
- endplot(); /* Terminate 3rd plot */
-
- EndOfApp:
- stopplot(); /* Quit and close files */
-
- FreeMem:
- GPC_FREE(&hx, &x); /* free allocated global memory */
- GPC_FREE(&hy, &y);
- GPC_FREE(&hz, &z);
- }
-